
package org.openeai.lite.console.actionhandlers;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.openeai.lite.common.control.BrokerController;
import org.openeai.lite.common.exception.OpenEAIException;


@ManagedBean(name = "brokerNewDestinationActionHandler")
@RequestScoped
public class BrokerNewDestinationActionHandler
{

    // Properties
    private String queue;

    private String topic;

    private String message;

    private String temporary;

    public String getQueue()
    {
        return queue;
    }

    public void setQueue(String queue)
    {
        this.queue = queue;
    }

    public String getTopic()
    {
        return topic;
    }

    public void setTopic(String topic)
    {
        this.topic = topic;
    }

    public String getTemporary()
    {
        return temporary;
    }

    public void setTemporary(String temporary)
    {
        this.temporary = temporary;
    }

    public String getMessage()
    {
        return this.message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    // Create new queue
    public void createQueue()
    {
        try
        {
            if (this.queue != null)
            {
                BrokerController.getInstance().createQueue(this.queue);
                setMessage("Queue " + this.queue + " created.");
                // Reset form items
                setQueue(null);
                setTemporary(null);
            }
            else
            {
                setMessage("Error creating queue!");
            }
        }
        catch (OpenEAIException oeu)
        {
            // handling and logging is done by backend logic
            ;
        }
    }

    // create new topic
    public void createTopic()
    {
        try
        {
            if (this.topic != null)
            {
                BrokerController.getInstance().createTopic(this.topic);
                setMessage("Topic " + this.topic + " created.");
                // Reset form items
                setTopic(null);
                setTemporary(null);
            }
            else
            {
                setMessage("Could not retreive topic name for creation.");
            }
        }
        catch (OpenEAIException oeu)
        {
            // handling and logging is done by backend logic
            ;
        }
    }

}
